#include <iostream>
#include <fstream>
#include "graph.h"

int buildGraph(graph* g, char* filePath, int vn);   //根据文件建立邻接表

int emailFile();
int jazzFile();

int main(int argc, char *argv[])
{
    (void)argc;
    (void)argv;

    //emailFile();
    jazzFile();


    return 0;
}


int emailFile()
{

    graph g;
    buildGraph(&g, (char*)"email.txt", 1133);
    g.getF();


    //不同节点组数量下感染规模比较
    std::cout << "coreNum:" << std::endl;

    g.setInfectRate(0.5);
    for(int t = 100; t <= 1000; t += 100)
    {
        std::cout << t << ":" << std::endl;
        g.setCoreNum(t);

        g.selectByDegree();
        g.infect();
        std::cout << "    degree:\t" << g.infectSize() << std::endl;

        g.selectByVote();
        g.infect();
        std::cout << "    vote:\t" << g.infectSize() << std::endl;
        std::cout << std::endl;
    }


    //不同感染率下感染规模的比较
    std::cout << "infectRate:" << std::endl;

    g.setCoreNum(500);
    for(double t = 0; t <= 1; t += 0.1)
    {
        std::cout << t << ":" << std::endl;
        g.setInfectRate(t);

        g.selectByDegree();
        g.infect();
        std::cout << "    degree:\t" << g.infectSize() << std::endl;

        g.selectByVote();
        g.infect();
        std::cout << "    vote:\t" << g.infectSize() << std::endl;
        std::cout << std::endl;
    }
    return 1;


}

int jazzFile()
{

    graph g;
    buildGraph(&g, (char*)"Jazz.txt", 198);
    g.getF();


    //不同节点组数量下感染规模比较
    std::cout << "coreNum:" << std::endl;

    g.setInfectRate(0.5);
    for(int t = 10; t <= 150; t += 10)
    {
        std::cout << t << ":" << std::endl;
        g.setCoreNum(t);

        g.selectByDegree();
        g.infect();
        std::cout << "    degree:\t" << g.infectSize() << std::endl;

        g.selectByVote();
        g.infect();
        std::cout << "    vote:\t" << g.infectSize() << std::endl;
        std::cout << std::endl;
    }


    //不同感染率下感染规模的比较
    std::cout << "infectRate:" << std::endl;

    g.setCoreNum(100);
    for(double t = 0; t <= 1; t += 0.1)
    {
        std::cout << t << ":" << std::endl;
        g.setInfectRate(t);

        g.selectByDegree();
        g.infect();
        std::cout << "    degree:\t" << g.infectSize() << std::endl;

        g.selectByVote();
        g.infect();
        std::cout << "    vote:\t" << g.infectSize() << std::endl;
        std::cout << std::endl;
    }
    return 1;

}

int buildGraph(graph *g, char *filePath, int vn)
{
    g->setVex(vn);

    std::fstream f;
    f.open(filePath, std::ios::in);
    if(!f)
        return 0;

    char l[20];
    int v1, v2;

    f.getline(l, 20);
    while(f.eof() == 0)
    {
        std::sscanf(l, "%d%d", &v1, &v2);
        //std::cout << v1 << " " << v2 << std::endl;
        g->addArc(v1, v2);
        f.getline(l, 20);
    }

    return 1;

}
